//
//  FZMCCacheManager.h
//  Pods
//
//  Created by 李灿 on 15/11/11.
//
//

#import <Foundation/Foundation.h>
#import "FZHomeCourseModel.h"
#import "SRBookRootModel.h"
#import "SRWorkDetailModel.h"

@class  FZMCCacheManager;

@protocol FZMCCacheManagerDelegate <NSObject>

@optional

/**
 *  上传进度回调
 *
 *  @param percent    进度
 */
-(void)MCCacheManager:(FZMCCacheManager *)cacheManager downloadPercentChangedWithModel:(FZHomeCourseModel*)model percent:(CGFloat)percent;
/**
 *  成功回调
 *
 *  @param model
 */
-(void)MCCacheManager:(FZMCCacheManager *)cacheManager downloadSuccessWithModel:(FZHomeCourseModel*)model;

/**
 *  上传牵牛时的失败回调
 *
 *  @param model
 *  @param msg        失败原因
 */
-(void)MCCacheManager:(FZMCCacheManager *)cacheManager downloadFailureWithModel:(FZHomeCourseModel*)model msg:(NSString*)msg;

@end

@interface FZMCCacheManager : NSObject

+ (instancetype)defaultManager;

@property (weak, nonatomic) id<FZMCCacheManagerDelegate> delegate;

@property (strong, nonatomic) NSMutableArray *books;//已经添加的课本

#pragma mark - Book Manager

- (void)addBook:(FZHomeCourseModel *)book;
- (void)removeBookAtIndex:(NSInteger)index;
- (void)removeBook:(FZHomeCourseModel *)book;
- (BOOL)isExistBook:(FZHomeCourseModel *)book;
- (BOOL)isExistBookForBookID:(NSString *)bookID;

- (void)removeAllBooks;

- (void)saveBookInfoToFile;
- (void)readBookInfoFromFile;
- (void)startDownloadBook:(FZHomeCourseModel *)bookModel;
    //下载音频文件，对于作品
- (void)downloadAudioWithWorkModel:(SRWorkDetailModel *)bookModel
                      successBlock:(MCSucessBlock)successBlock
                      failureBlock:(MCFailureBlock)failureBlock
                     progressBlock:(MCProgressBlock)progressBlock;

- (void)parseGuideBook;

- (BOOL)isExistBookFile:(FZHomeCourseModel *)bookModel;
- (SRBookRootModel *)readBookModelFromDocumentWithBookID:(NSString *)bookID;

+ (UIImage *)pageImageWithName:(NSString *)imageName bookID:(NSString *)bookID;
+ (NSString *)mp3PathWithName:(NSString *)mp3Name bookID:(NSString *)bookID;
+ (UIImage *)bookTitleImageWithBookID:(NSString *)bookID;

    //录音文件相关
+ (NSString *)audioRecordFilePathWithTrackID:(NSString *)trackID pageID:(NSString *)pageID bookID:(NSString *)bookID;

+ (NSString *)recordMp3FilePathWithTrackID:(NSString *)trackID pageID:(NSString *)pageID bookID:(NSString *)bookID;
+ (BOOL )removeMp3FilePathWithTrackID:(NSString *)trackID pageID:(NSString *)pageID bookID:(NSString *)bookID;

    //返回文件路径
+ (NSString *)isExistMp3FilePathWithTrackID:(NSString *)trackID pageID:(NSString *)pageID bookID:(NSString *)bookID;

    //合成音频文件路径
+ (NSString *)recordComposeAudioFilePathWithCatalogueID:(NSString *)CatalogueID bookID:(NSString *)bookID;
+ (NSString *)recordPageDirPathWithPageID:(NSString *)pageID bookID:(NSString *)bookID;
+ (NSString *)recordMp3AudioFilePathWithCatalogueID:(NSString *)CatalogueID bookID:(NSString *)bookID;
+ (NSString *)isExistMp3FilePathWithShowID:(NSString *)showID;
+ (NSString *)recordMp3FilePathWithProblemID:(NSString *)ProblemID;


#pragma mark - File Handle

+ (BOOL)createDirWithPath:(NSString *)path;
+ (NSString*)filePathAtCacheForFileName:(NSString*)fileName;

// 计算单个文件大小
+ (float)fileCacheSizeAtPath:(NSString *)filePath;

// 计算指定文件夹的缓存大小
+ (float)folderCacheSizeAtPath:(NSString *)filePath;

// 计算Documents文件夹的缓存大小
+ (float)documentsCacheSizeAtPath;

// 计算cache文件夹的缓存大小
+ (float)cacheSizeAtPath;

// 计算卡片文件夹的缓存大小
+ (float)cardCacheSizePath;

// 删除指定文件缓存
+ (void)removeFileCache:(NSString *)filePath;

// 删除指定文件夹缓存
+ (void)removefolderFileCache:(NSString *)filePath;

// 删除Documents文件夹缓存
+ (void)removeDocumentsFileCache;

// 删除cache文件夹缓存
+ (void)removeCacheFileCache;

// 删除所有网络缓存
+ (void)removeCache;

//删除上传录音的缓存
+ (void)removeUploadRecordCache;

// 解压文件
+ (BOOL)zipArchiveFilePath:(NSString *)path toPath:(NSString *)toPath;


@end
